package com.msh.starter.common.web.config;

import com.msh.frame.client.interfaces.IClassLoadLog;
import com.msh.frame.web.handler.ResultHandlerExceptionResolver;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author shihu
 * @mail m-sh@qq.com
 */
@ConditionalOnProperty(name = "msh.starter.web.exception", havingValue = "true", matchIfMissing = true)
@Component
public class ExceptionConfig implements WebMvcConfigurer, IClassLoadLog {

  @Override
  public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
    resolvers.add(0, new ResultHandlerExceptionResolver());
  }

  @Override
  public String logInfo() {
    return new StringBuilder()
        .append("----执行类 ")
        .append(ExceptionConfig.class)
        .append("\r\n")
        .append("--------加载类 ")
        .append(ExceptionConfig.class)
        .append("\r\n")
        .toString();
  }
}
